/* ========================================================================== */
/*   Log.cpp                           			                              */
/*   (c) 2012 Team 7 Hogeschool Utrecht ICT TI                                */
/*		Lars Stolwijk, Gerben Boot, Guido van Hienen, Marcel Boelen			  */
/*                                                                            */
/*   Logs the Gametime, Health and WeaponID when the player gets hit. Resets  */
/*		and gets entire log when requested.								      */
/* ========================================================================== */
#include "Log.h"

void Log::main()
{	
	for(;;)
	{
		RTOS::event e = wait( );
		if(ClearLogFlag == e)
		{
			for(unsigned int i = 0; i < 50; i++)
			{	
				log[i].player = 0;
				log[i].weapon = 0;
				log[i].health = 0;
				log[i].time = 0;
			}
			logCount = 0;
		}
		else if(GetLogFlag == e)
		{
			theReadLogHandler->WriteLog(log);
		}
		else if(LogChannel == e)
		{
			LogLine le = LogChannel.read();
			log[(short)logCount] = le;
			logCount++;
		}
	}
}

void Log::ClearLog()
{
	ClearLogFlag.set();
}

void Log::GetLog()
{
	GetLogFlag.set();
}

void Log::WriteLog(char p, char w, char h, short t)
{
	LogChannel.write(LogLine(p, w, h, t));
}
